package com.apes.fico.masterdata.gl.respository;

import com.apes.framework.jpa.repository.CustomRepository;
import com.apes.fico.masterdata.gl.model.AccountingPeriod;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
import java.util.Map;

public interface AccountingPeriodRepository extends CustomRepository<AccountingPeriod, String> {

    AccountingPeriod findByCompany_IdAndYear(String id, int year);

    List<AccountingPeriod> findByCompany_Id(String id);

    @Query(value = " select C.* from mas_acc_period_item C,mas_acc_period D where D.ID= C.acc_period_id  and C.Year_month >= (" +
            "select min(YEAR_MONTH) from  mas_acc_period_item A,mas_acc_period B where B.ID= A.acc_period_id " +
            "and  A.CARRY_OVER_PL_FLAG = 0 and B.Company_Id = :company)" +
            "and D.Company_Id = :company and c.CARRY_OVER_PL_FLAG =0 ", nativeQuery = true)
    List<Map> finAccountingPeriodItems(@Param("company") String company);

}
